﻿#pragma once


#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "hyMutiplayer/Blaster/Weapon/Weapon.h"
#include "CoreUObject.h"
#include "hyMutiplayer/Blaster/Character/BlasterCharacter.h"
#include "CombatComponent.generated.h"


#define GENERATED_BODY()
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MUTIPLAYERBLASTER_API UCombatComponent : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UCombatComponent();
	
	friend class ABlasterCharacter;
	friend class UBlasterCharacter; //友元函数,赋予该类所有权限
	virtual void TickComponment(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTick);
	

protected:
	
	//~UCombatComponent();
	// Called when the game starts
	virtual void BeginPlay() override;

	UFUNCTION()
	void OnRep_EquippedWeapon();

	UFUNCTION(Server,Reliable)
	void ServerSetAiming(bool bIsAiming);
	
public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;


	virtual void EquipWeapon(AWeapon * WeaponToEquip);
	void SetAiming(bool bIsAiming);
	void ServerSetAiming_Implementation(bool bIsAiming);
	void SetAiming(bool bIsAiming, bool& bAiming) ;

private:
	
	ABlasterCharacter* Character;
	UPROPERTY(ReplicatedUsing = OnRep_EquippedWeapon)
	AWeapon * EquippedWeapon;
	bool bAiming;

//行走速度
	float BaseWalkSpeed;
	float AimingSpeed;
};

